package com.example.service;

import com.example.dao.StudentDao;
import com.example.dao.TypeDao;
import com.example.entity.Book;
import com.example.entity.Params;
import com.example.entity.Student;
import com.example.entity.Type;
import com.example.entity.dto.UserDTO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
@Slf4j
@RequiredArgsConstructor
public class StudentService {

    private final StudentDao studentDao;



    public void add(Student student) {
        studentDao.insertSelective(student);
    }

//    public void update(Type type) {
//        typeDao.updateByPrimaryKeySelective(type);
//    }

    public PageInfo<Student> findBySearch(Params params) {
        // 开启分页查询
        PageHelper.startPage(params.getPageNum(), params.getPageSize());
        // 接下来的查询会自动按照当前开启的分页设置来查询
        List<Student> list = studentDao.findBySearch(params);
        log.info("{}",list);
        return PageInfo.of(list);
    }

    public void delete(Integer id) {
        studentDao.deleteByPrimaryKey(id);
    }


    /**
     *根据姓名考号身份证在学生表中查找是否存在该学生
     * @param book
     * @return
     */
    public Student getBy(UserDTO book) {
       Student student =studentDao.getBy(book);
        return student;
    }

    /**
     * book每提交一次count加一
     */
    public void updataCount(UserDTO book) {
        studentDao.updataCount(book);
    }


//
//    public List<Type> findAll() {
//        return typeDao.selectAll();
//    }
}
